'use strict';

var formatDate = require('./format-date'),
    Money = require('../models/money');

var path = require('path'),
    fs = require('fs');

function getExportFile() {
    return path.join(__dirname, '../../data/', formatDate(Date.now()) + '.json');
}

Money.getInfo(function(err, info) {
    if (err) {
        throw err;
    }

    var result = info.data.map(function(item) {
        return {
            currency: item.currency,
            date: formatDate(item.date),
            category: item.category,
            event: item.event,
            note: item.note,
            money: item.money,
            order: item.order

        };
    });

    var newFile = getExportFile();
    fs.writeFileSync(newFile, JSON.stringify(result, null, 4));
});
